package com.sm.dao;

import com.sm.entity.Wages;
import com.sm.entity.WagesLevel;
import com.sm.entity.Welfare;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface WagesDao {
    //查找
    @Select("select * from wages where month = #{month}")
    @Results({
            @Result(property = "userInfo" ,column = "uid",one = @One(select = "com.sm.dao.UserDao.findByUid"))
    })
    public List<Wages> fingAllWages(Integer month);

    //查询当月的工资表
    @Select("select * from wages where uid = #{uid} and month = #{month}")
    @Results({
            @Result(property = "userInfo" ,column = "uid",one = @One(select = "com.sm.dao.UserDao.findByUid"))
    })
    public Wages findWagesByUid(@Param("uid") Integer uid ,@Param("month")Integer month);

    //查询职务工资和福利金额
    @Select("select welfare from wages where uid = #{uid} and month = #{month}")
    public Double findWelfareByUid(@Param("uid")Integer uid ,@Param("month")Integer month);

    //添加员工工资表
//    @Options(useGeneratedKeys = true, keyProperty = "wid", keyColumn = "wid")
    @Insert("insert into wages(uid,month) values(#{uid},#{month})")
    public void addWages(@Param("uid")Integer uid,@Param("month")Integer month);

    //修改
    //修改福利金额
    @Update("update wages set welfare = welfare + #{welAmount} where uid = #{uid} and month = #{month}")
    public void updateWelfare(@Param("uid") Integer uid,@Param("welAmount") Double welAmount,@Param("month")Integer month);

    //修改工资
    @Update("<script>" +
            "update wages " +
            "<set> " +
            " <if test='baseSalary != null'>baseSalary = #{baseSalary,jdbcType=DOUBLE},</if> " +
            " <if test='jobSalary != null'>jobSalary = #{jobSalary,jdbcType=DOUBLE},</if> " +
            " <if test='wagePayable != null'>wagePayable = #{wagePayable,jdbcType=DOUBLE},</if> " +
            " <if test='wageReal != null'>wageReal = #{wageReal,jdbcType=DOUBLE},</if> " +
            " </set> " +
            "where uid = #{userInfo.uid} and month = #{month}" +
            "</script>")
    public void updateWages(Wages wages)throws Exception;

    //置零
    @Update("update wages set baseSalary = 0,jobSalary = 0, welfare = 0, wagePayable = 0, wageReal = 0 where month = #{month}")
    public void deleteWages(Integer month)throws Exception;

    //删除
    @Delete("delete from wages where uid = #{uid} and month = #{month}")
    public void clearWages(@Param("uid")Integer uid,@Param("month")Integer month)throws Exception;

    //添加
//    //添加员工工资表
//    @Options(useGeneratedKeys = true, keyProperty = "wid", keyColumn = "wid")
//    @Insert("insert into wages(uid,baseSalary,jobSalary,month) values(#{userInfo.uid},#{baseSalary},#{jobSalary},#{month})")
//    public void addWages(Wages wages);
//    //修改基本工资
//    @Update("update wages set baseSalary = #{baseSalary} where uid = #{uid} and month = #{month}")
//    public void updateBaseSalary(@Param("uid")Integer uid,@Param("baseSalary")Double baseSalary,@Param("month")Integer month);
//
//    //修改职务工资
//    @Update("update wages set jobSalary = #{jobSalary} where uid = #{uid} and month = #{month}")
//    public void updateJobSalary(@Param("uid")Integer uid,@Param("jobSalary")Double jobSalary,@Param("month")Integer month);

//    //修改职务工资   修改基本工资
//    @Update("update wages set jobSalary = #{jobSalary},baseSalary = #{baseSalary} where uid = #{uid} and month = #{month}")
//    public void updateSalary(Wages wages);

//    //修改应发工资
//    @Update("update wages set wagePayable = #{wagePayable} where uid = #{uid} and month = #{month}")
//    public void updateWagePayable(@Param("uid")Integer uid,@Param("wagePayable")Double wagePayable,@Param("month")Integer month);
//
//    //修改实发工资
//    @Update("update wages set wageReal = #{wageReal} where uid = #{uid} and month = #{month}")
//    public void updateWageReal(@Param("uid")Integer uid,@Param("wageReal")Double wageReal,@Param("month")Integer month);
}
